package com.hailiao.beidou.message.service

import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import androidx.core.app.NotificationCompat
import com.d10ng.app.managers.NotificationController

/**
 * 通知类型
 * TODO: 需要优化
 * @Author d10ng
 * @Date 2023/11/29 18:58
 */
enum class NotificationType(
    // 消息ID
    val nId: String,
    // 消息名称
    val nameStr: String,
    // 重要程度，Android O以上使用
    val importance: Int,
    // 是否点击隐藏
    val isAutoCancel: Boolean,
    // 是否震动
    val isVibrationEnable: Boolean,
    // 是否响铃
    val isVoiceEnable: Boolean,
    // 是否灯光显示
    val isLightEnable: Boolean,
    // 锁屏显示规则
    val lockScreenVisibility: Int,
    // 是否绕过勿扰模式
    val isCanByPassDnd: Boolean,
    // 通知是否允许进行应用角标数量统计
    val isShowBadge: Boolean
) {

    // 聊天消息
    CHAT_MSG(
        "chat_msg",
        "聊天消息通知",
        NotificationManager.IMPORTANCE_HIGH,
        true,
        true,
        true,
        true,
        Notification.VISIBILITY_SECRET,
        false,
        true
    ),

    // 位置汇报消息
    LOCATION_REPORT_MSG(
        "location_report_msg",
        "执行位置汇报通知",
        NotificationManager.IMPORTANCE_DEFAULT,
        false,
        true,
        true,
        false,
        Notification.VISIBILITY_PUBLIC,
        false,
        false
    ),

    // SOS消息
    SOS_MSG(
        "SOS_msg",
        "执行SOS通知",
        NotificationManager.IMPORTANCE_DEFAULT,
        false,
        true,
        true,
        true,
        Notification.VISIBILITY_PUBLIC,
        true,
        false
    ),
}

/**
 * 创建消息
 * @param type NotificationType
 * @param notifyId Int
 * @param title String
 * @param content String
 * @param iconResId Int
 * @param hasProgress Boolean
 * @param max Int
 * @param progress Int
 * @param indeterminate Boolean
 * @param tapIntent PendingIntent?
 * @return NotificationCompat.Builder
 */
fun createNotification(
    type: NotificationType,
    notifyId: Int,
    title: String,
    content: String,
    iconResId: Int,
    hasProgress: Boolean = false,
    max: Int = 100,
    progress: Int = 0,
    indeterminate: Boolean = false,
    tapIntent: PendingIntent? = null
): NotificationCompat.Builder {
    if (hasProgress) {
        return NotificationController.createProgressWithChannel(
            channelId = type.nId,
            channelName = type.nameStr,
            channelImportance = type.importance,
            notifyId = notifyId,
            title = title,
            content = content,
            smallIcon = iconResId,
            max = max,
            progress = progress,
            indeterminate = indeterminate
        )
    } else {
        return NotificationController.createStandardWithChannel(
            channelId = type.nId,
            channelName = type.nameStr,
            channelImportance = type.importance,
            notifyId = notifyId,
            title = title,
            content = content,
            smallIcon = iconResId,
            tapIntent = tapIntent
        )
    }
}